define(function (require, exports) {
	var pubjs = require('pubjs');
	var $ = require('jquery');
	var grid = require('@base/highGrid');
	// var util = require('util');

	// 资质审核列表
	var Base = grid.base.extend({
		init: function (config) {
			config = pubjs.conf(config, {
				url: 'qualification/list',
				urlAudit: 'qualification/getVerifyState',
				// 移除url
				urlRemove: 'qualification/remove',
				reqType: 'websocket',
				hasTab: false,
				hasAmount: false,
				hasSearch: false,
				hasSwitch: false,
				hasExport: false,
				hasMenu: false,
				hasRefresh: true,
				hasSubGrid: false,
				hasSelect: false,
				hasPager: true,
				auto_load: true,
				cols: [
					{name: '_id', text: LANG("ID"), width: 60, align: 'center'},
					{name: "UserName", text: LANG("公司名称"), align: 'left', width: 250, render: 'renderCName'},
					{
						name: 'verifyStatus',
						text: LANG("审核状态"),
						align: 'center',
						width: 65,
						render: 'renderVerifyStatus'
					},
					{name: "SiteName", text: LANG("网站名"), align: 'left', width: 200, render: 'renderName'},
					{name: "SiteUrl", text: LANG("网址"), align: 'left', render: 'renderName', width: 250}
				],
				metrics: [
					{name: "CreateUserName", text: LANG("品牌名称"), align: 'left', render: 'renderSource'},
					{name: "IsSlave", text: LANG("类型"), align: 'center', render: 'renderType'}
					// {name:"operator", text:LANG("操作"), align:'center', render:'renderOperator'}
				],
				param: {
					order: 'CreateTime|-1'
				},
				gridName: 'aptitude'
			});

			this.Super('init', arguments);
		},
		afterBuild: function () {
			this.Super('afterBuild', arguments);
			this.uiProxy('.P-adminAptitudeBtnVerify', 'click', 'eventShowStatus');
		},
		renderType: function (i, val, row, con) {
			var append = '';
			if (row.BrandName) {
				append = LANG('【品牌 %1】', row.BrandName);
			}

			return (!val ? LANG('主资质') : LANG('从资质')) + append;
		},
		renderVerifyStatus: function (i, val, row, con) {
			var elm = $('<a class="P-adminAptitudeBtnVerify" data-id="' + row._id + '"/>');
			elm.attr('title', LANG("点击查看"));
			return elm;
		},
		renderCName: function (i, val, row, con) {
			val = LANG(val) || '';

			var html;

			if (pubjs.checkRight('qualification.update')) {
				html = $('<a class="db text-truncate" title="' + val + '">' + val + '</a>').attr({
					'href': '#admin/aptitude/edit/' + row._id,
					'target': '_blank'
				});
			} else {
				html = $('<div class="text-truncate" title="' + val + '">' + val + '</div>');
			}

			return html;
		},
		renderName: function (i, val, row, con) {
			val = LANG(val) || '';
			var html = $('<div class="text-truncate" title="' + val + '">' + val + '</div>');
			return html;
		},
		renderSource: function (i, val, row) {
			var name = LANG(val) || '-';
			var title = LANG("所属公司：") + name;

			return [
				'<div class="M-tableListWidthLimit w180 mb0" title="' + title + '">',
				name,
				'</div>'
			].join('');
		},
		// 审核状态图标点击，通知父模块展示tooltip
		eventShowStatus: function (evt, elm) {
			var $elm = $(elm);
			var id = $elm.attr('data-id');
			this.fire('showStatusTip', {
				id: +id,
				elm: $elm,
				clientY: evt.clientY
			});
		}
	})
	exports.base = Base;
});